package view.menus;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import controller.CustomEvent;
import controller.RightClickMenuEventHandler;
/** * A class to encapsulate the right click menu on designer * @author Daniel Bond, Mohammed Abdullah, Gideon Pyzer * */
@SuppressWarnings("serial")
public class RightClickMenu extends JPopupMenu
{
	private JMenuItem mrObjectDelete;
	private JMenuItem mrObjectEditText;
	private JMenuItem mrObjectLineColour;
	private JMenuItem mrObjectFillColour;
	private JMenuItem mrObjectTextColour;
	private JMenuItem mrObjectTransparent;
	private JMenuItem mrObjectSendToBack;
	private JMenuItem mrObjectBringToFront;
	private RightClickMenuEventHandler eventHandler;
	public RightClickMenu()
	{
		super();
		eventHandler = new RightClickMenuEventHandler();
		mrObjectDelete = new JMenuItem("Delete");
		mrObjectEditText = new JMenuItem("Edit Text");
		mrObjectLineColour = new JMenuItem("Line Colour");
		mrObjectFillColour = new JMenuItem("Fill Colour");
		mrObjectTextColour = new JMenuItem("Text Colour");
		mrObjectTransparent = new JMenuItem("Transparent");
		mrObjectSendToBack = new JMenuItem("Send To Back");
		mrObjectBringToFront = new JMenuItem("Bring To Front");
		buildMenu();
		mrObjectDelete.addActionListener(new ActionListener(){	//Delete Current selected Object
			public void actionPerformed(ActionEvent e){	
				CustomEvent event = new CustomEvent("objectDelete");
				RightClickMenu.this.eventHandler.createEvent(event);
			}
		});
		mrObjectEditText.addActionListener(new ActionListener(){//Edit text inside current object
			public void actionPerformed(ActionEvent e){
				CustomEvent event = new CustomEvent("objectEditText");
				RightClickMenu.this.eventHandler.createEvent(event);
			}
		});
		mrObjectLineColour.addActionListener(new ActionListener(){//Change the line colour of the selected object
			public void actionPerformed(ActionEvent e){
				CustomEvent event = new CustomEvent("objectLineColour");
				RightClickMenu.this.eventHandler.createEvent(event);
			}
		});
		mrObjectFillColour.addActionListener(new ActionListener(){//Change the fill colour of the selected object
			public void actionPerformed(ActionEvent e){
				CustomEvent event = new CustomEvent("objectFillColour");
				RightClickMenu.this.eventHandler.createEvent(event);
			}
		});
		
		mrObjectTextColour.addActionListener(new ActionListener(){//Change the text colour of the selected object
			public void actionPerformed(ActionEvent e){
				CustomEvent event = new CustomEvent("objectTextColour");
				RightClickMenu.this.eventHandler.createEvent(event);
			}
		});
		mrObjectTransparent.addActionListener(new ActionListener(){//Change whether the object is transparent of opaque
			public void actionPerformed(ActionEvent e){
				CustomEvent event = new CustomEvent("objectTransparent");
				RightClickMenu.this.eventHandler.createEvent(event);
			}
		});
		mrObjectSendToBack.addActionListener(new ActionListener(){//Send the object to the back of the layout
			public void actionPerformed(ActionEvent e){
				CustomEvent event = new CustomEvent("objectSendToBack");
				RightClickMenu.this.eventHandler.createEvent(event);
			}
		});
		mrObjectBringToFront.addActionListener(new ActionListener(){//Bring the object to the front of the object
			public void actionPerformed(ActionEvent e){
				CustomEvent event = new CustomEvent("objectBringToFront");
				RightClickMenu.this.eventHandler.createEvent(event);
			}
		});
	}	/**	 * Adds the components to the menu	 */
	private void buildMenu(){
	
		this.add(mrObjectDelete);
		this.addSeparator();
		this.add(mrObjectEditText);
		this.addSeparator();
		this.add(mrObjectLineColour);
		this.add(mrObjectFillColour);
		this.add(mrObjectTextColour);
		this.addSeparator();
		this.add(mrObjectTransparent);
		this.addSeparator();
		this.add(mrObjectSendToBack);
		this.add(mrObjectBringToFront);
	}	/**	 * Sets the transparent text	 * @param text the text to be set as transparent.	 */
	public void setTransparentText(String text){
		mrObjectTransparent.setText(text);
	}
}